package org.htzb.news.web;

import org.htzb.news.entity.Comment;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CommentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        req.setCharacterEncoding("utf-8");
        String opr= req.getParameter("opr");
        if(opr==null){
            opr="listComments";
        }
        if(opr.equals("listComments")){
            String id = req.getParameter("nid");
            String author = req.getParameter("cauthor");
            String ip = req.getParameter("cip");
            String content = req.getParameter("ccontent");
            Date date= new Date();
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateStr=sdf.format(date);

            Comment comment=new Comment(Integer.parseInt(id),author,ip,content,dateStr);


        }

    }
}
